import java.util.concurrent.Semaphore;

class Mycount {
    public int count;

    public void increase() {
        count++;
    }
}

public class Thread53 {
    public static void main(String[] args) {
        Mycount mycount=new Mycount();
        Semaphore semphore=new Semaphore(1);
        Thread t1=new Thread(()->{
            for(int i=0;i<20;i++)
            {
                mycount.increase();

            }
            semphore.release();

        });
        Thread t2=new Thread(()->{
            for(int j=0;j<20;j++)
            {
                mycount.increase();
            }
            semphore.release();

        });
        t1.start();
        try {
            semphore.acquire();
            semphore.acquire();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        t2.start();
        try {
            semphore.acquire();
            semphore.acquire();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(mycount.count);



    }
}
